#include <QWebHistory>
#include "webhistorycompleter.h"

class WebHistoryIndex: public QModelIndex
{

};

WebHistoryModel::WebHistoryModel(QObject *parent, QWebHistory *history)
	: QAbstractListModel(parent),
	m_history(history)
{
}

int WebHistoryModel::rowCount(const QModelIndex &index) const
{
	if (m_history==NULL)
		return -1;
	int i = m_history->items().count();
	qDebug("%d - %s, %s() = %d", __LINE__, __FILE__, __FUNCTION__, i);
	return i;
}

QVariant WebHistoryModel::data(const QModelIndex & index, int role) const
{
	switch (role){
	case Qt::DisplayRole:
		if (index.column()>=1)
			return QVariant();
		if (index.row()>= m_history->items().count())
			return QVariant();

		qDebug("%d - %s, %s() = %s", __LINE__, __FILE__, __FUNCTION__, qPrintable(m_history->itemAt(index.row()).url().toString()) );
		return m_history->itemAt(index.row()).url().toString();
		break;
	}

	return QVariant();
}

void	WebHistoryModel::setWebHistory(QWebHistory *history)
{
	m_history = history;
	reset();
}

void	WebHistoryModel::refetchHistory()
{
	beginResetModel();
//	reset();
	endResetModel();
//	revert();
}

WebHistoryCompleter::WebHistoryCompleter()
{
}
